#import "KawaUmengPlugin.h"
#import <UMCommon/UMCommon.h>
#import <UMCommon/MobClick.h>

@implementation KawaUmengPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"kawa_umeng" binaryMessenger:[registrar messenger]];
    KawaUmengPlugin *instance = [[KawaUmengPlugin alloc] init];
    [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result{
    NSString *method = call.method;
    id args = call.arguments;
    if ([method isEqualToString:@"init"]) {
        [UMConfigure initWithAppkey:[args valueForKey:@"appkey"] channel:@"AppStore"];
        result(@(YES));
    }else if ([method isEqualToString:@"openDebug"]){
        [UMConfigure setLogEnabled:[[args valueForKey:@"isDebug"] isEqualToString:@"1"]];
        result(@(YES));
    }else if ([method isEqualToString:@"pageStart"]){
        [MobClick beginLogPageView:[args valueForKey:@"page"]];
        result(@(YES));
    }else if ([method isEqualToString:@"pageEnd"]){
        [MobClick endLogPageView:[args valueForKey:@"page"]];
        result(@(YES));
    }else if ([method isEqualToString:@"eventCount"]){
        NSMutableDictionary *dict = [args mutableCopy];
        [dict removeObjectForKey:@"key"];
        [MobClick event:[args valueForKey:@"key"] attributes:dict];
        result(@(YES));
    }else if ([method isEqualToString:@"event"]){
        [MobClick event:[args valueForKey:@"key"]];
        result(@(YES));
    }else{
        result(@(YES));
    }
}

@end
